<script setup lang="ts">
import { useRouter } from 'vue-router'

const router = useRouter()

const props = defineProps<{
  title?: string
  rightText?: string
}>()

const emit = defineEmits<{
  (e: 'click-right'): void
}>()

const handleClickLeft = (): void => {
  console.log(history.state.back)
  history.state.back ? router.back() : router.push({ path: '/user' })
}

const handleClickRight = (): void => {
  emit('click-right')
}
</script>

<template>
  <van-nav-bar
    :title="title"
    :right-text="props.rightText"
    left-arrow
    fixed
    @click-left="handleClickLeft"
    @click-right="handleClickRight"
  ></van-nav-bar>
</template>

<style lang="scss" scoped>
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
